package com.yunyan.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    // 静态资源配置 。 校徽访问 URL
    private static final String UPLOADED_FOLDER = System.getProperty("user.dir") + "/src/main/resources/static/";


    @Resource
    private WebInterceptor interceptor;


    /**
     * 配置添加拦截器，拦截是否登录以及角色权限
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(interceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/load/*")
                .excludePathPatterns("/upload/**");
    }



    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/**").addResourceLocations("file:" + UPLOADED_FOLDER);
    }
}